{extend name="public/base"/}
{block name="style"}
<link rel="stylesheet" href="__PUBLIC__/plugs/bootstrap-select/css/bootstrap-select.css">
<link rel="stylesheet" type="text/css" href="__PUBLIC__/plugs/webuploader/webuploader.css">
<link rel="stylesheet" href="__PUBLIC__/static/layui/css/layui.css">
<style>
    a:hover{text-decoration: none;}
</style>
{/block}
{block name="body"}
<div class="main-box clearfix">
	<header class="main-box-header clearfix">
		<div class="pull-left" style="width:50%">
            <form method="get">
                <div class="col-sm-12 col-md-4 col-lg-3" style="padding-left:0">
                    <input type="text" class="form-control" name="keyword" value="{$keyword|default=''}" placeholder="请输入关键字">
                </div>
                <div class="col-sm-12 col-md-4 col-lg-3">
                    <select name="memberId" id="memberId" class="selectpicker" data-live-search="true">
                        <option value="">全部</option>
                        {foreach name="cp_member" item="vo" key="k" }
                            <option value="{$vo.uid}" {if input('get.memberId')==$vo.uid}selected {/if}>{$vo.nickname}</option>
                        {/foreach}
                    </select>
                </div>
                <div class="col-sm-12 col-md-4">
                    <button class="btn btn-primary" type="submit">搜索</button>
                </div>
            </form>
		</div>
		<div class="pull-right">
            <a class="btn btn-primary add" href="javascript:;">上传</a>
            <a class="btn btn-info batchDownload" href="javascript:;">批量下载</a>
            <a class="btn btn-danger ajax-post confirm" url="{:url('del')}" target-form="row-selected">删 除</a>
		</div>
	</header>
	<div class="main-box-body clearfix">
        <div class="row">
            <div class="col-md-6">
                <table class="table table-hover table-bordered">
                    <thead>
                        <tr>
                            <th width="2%">
                                <input class="checkbox check-all" type="checkbox" style="display: inline-block;margin-top: -2px;vertical-align: middle;">
                            </th>
                            <th width="5%" class="text-center">ID</th>
                            <th width="33%">文件名</th></th>
                            <th width="15%">小说源站</th></th>
                            <th width="25%">上传时间</th></th>
                            <th width="20%">操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        {volist name="list" id="item"}
                        {eq name="mod" value="0"}
                            <tr style="font-size: 12px;">
                                <td>
                                    <input class="ids row-selected" type="checkbox" name="id[]" data-name="{$item['name']}" data-url="{$item['url']}" value="{$item['id']}">
                                </td>
                                <td class="text-center">{$item['id']}</td>
                                <td>{$item['name']}</td>
                                <td>{$item['memberName']}</td>
                                <td>{$item['create_time'] | date='Y-m-d H:i:s',###}</td>
                                <td>
                                    <a href="JavaScript:;" style="margin-right:5px" data-name="{$item.name}" data-url="{$item.url}" class="downLoad"><i class="fa fa-download"></i>下载</a>
                                    <a href="{:url('del',array('id'=>$item['id']))}" style="color:red;" class="ajax-get confirm"><i class="fa fa-times"></i> 删除</a>
                                </td>
                            </tr>
                        {/eq}
                        {/volist}
                    </tbody>
                </table>
            </div>
            <div class="col-md-6">
                <table class="table table-hover table-bordered">
                    <thead>
                        <tr>
                            <th width="2%">
                                <input class="checkbox check-all1" type="checkbox" style="display: inline-block;margin-top: -2px;vertical-align: middle;">
                            </th>
                            <th width="5%" class="text-center">ID</th>
                            <th width="33%">文件名</th></th>
                            <th width="15%">小说源站</th></th>
                            <th width="25%">上传时间</th></th>
                            <th width="20%">操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        {volist name="list" id="item"}
                        {eq name="mod" value="1"}
                            <tr style="font-size: 12px;">
                                <td>
                                    <input class="ids1 row-selected" type="checkbox" name="id[]" data-name="{$item['name']}" data-url="{$item['url']}" value="{$item['id']}">
                                </td>
                                <td class="text-center">{$item['id']}</td>
                                <td>{$item['name']}</td>
                                <td>{$item['memberName']}</td>
                                <td>{$item['create_time'] | date='Y-m-d H:i:s',###}</td>
                                <td>
                                    <a href="JavaScript:;" style="margin-right:5px" data-name="{$item.name}" data-url="{$item.url}" class="downLoad"><i class="fa fa-download"></i>下载</a>
                                    <a href="{:url('del',array('id'=>$item['id']))}" style="color:red;" class="ajax-get confirm"><i class="fa fa-times"></i> 删除</a>
                                </td>
                            </tr>
                        {/eq}
                        {/volist}
                    </tbody>
                </table>
            </div>
        </div>
        <div id="page" style="text-align: center;"></div>
	</div>

    <div class="modal fade" id="create-modal">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">×</span></button>
                    <span style="font-size: 20px;"><span id="referralname">添加</span></span>
                </div>
                <div class="modal-body">
                    <div data-bind="visible: loading" class="loading-panel" style="display: none;">
                        <i class="fa fa-spin fa-spinner"></i>
                    </div>
                    <form class="form-horizontal modelform">
                        <div class="row">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="control-label col-sm-4">小说源站</label>
                                    <div class="col-lg-8">
                                        <select name="memberId" id="memberId" class="selectpicker multipleSelete" data-live-search="true">
                                            <option value="">请选择</option>
                                            {foreach name="cp_member" item="vo" key="k" }
                                            <option value="{$vo.uid}">{$vo.nickname}</option>
                                            {/foreach}
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="control-label col-sm-4"><span class="required" style="color: red">*</span>上传文件</label>
                                    <div class="col-lg-8">
                                        <div class="picker-box">
                                            <div id="picker_ebook" class="picker_button">上传文案 </div>
                                            <input type="hidden" name="url" id="field_ebook" value="">
                                            <input type="hidden" name="name" id="name" value="">
                                            <div id="fileList_ebook" class="upload-file-list-info" >(请上传.txt文件)</div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" id="createTxt" class="btn btn-primary ">提交</button>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script type="text/javascript" src="__PUBLIC__/plugs/bootstrap-select/js/bootstrap-select.js"></script>
<script type="text/javascript" src="__PUBLIC__/plugs/webuploader/webuploader.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/plugs/webuploader/webuploader.custom.js"></script>
<script type="text/javascript" src="__PUBLIC__/static/layui/layui.js" ></script>
<script type="text/javascript">
    $('.add').click(function () {
        var $modal = $('#create-modal');
        $modal.on('shown.bs.modal', function () {
			//默认选择外
			$('#picker_ebook').html('<div>上传文案</div>')
			$("#picker_ebook").SentUploader({
				server:"{:url('Noveltxt/Uploadtxt')}",
				fileNumLimit:100,
                uploadEvents: {
					uploadComplete:function(file){
                        $('#name').val($('#name').val() ? $('#name').val()+','+file.name : file.name)
                    }
				},
				listName : 'fileList_ebook',
				hiddenName: 'field_ebook',
				hiddenValType:2,
				fileSingleSizeLimit:50*1024*1024,
				closeX:true
			});
		});	
        $modal.modal({ backdrop: 'static', keyboard: false })
    })

    $("#createTxt").on('click',function(){
        var data = $('.modelform').serializeJson();
        $.ajax({
            type: "POST",
            url: "{:url('Noveltxt/add')}",
            data,
            dataType: "json",
            success: function(data){
                if(data.code==1){
                    updateAlert(data.msg, 'success');
                    setTimeout(function() {
                        window.location.reload();
                    }, 100);
                }else{
                    updateAlert("添加，"+data.msg, 'danger');
                }
            },
        })
    });
    // 下载
    $('.downLoad').click(function(){
		download($(this).data('name'),$(this).data('url'))
	})
    // 批量下载
    $('.batchDownload').click(function(){
        $('.row-selected').each(function(item){
            if(this.checked){
                download($(this).data('name'),$(this).data('url'))
            }
        })
    })
    function download(name, href) {
		let aDom = document.createElement('a');
		aDom.style.display = 'none';
		aDom.href = 'http://'+window.location.host+'/'+href;
		aDom.setAttribute('download', name);
		document.body.appendChild(aDom);aDom.click();
		document.body.removeChild(aDom);
    }

    layui.use(['laypage', 'layer'], function () {
        var laypage = layui.laypage,
            layer = layui.layer;
        // 版本
        laypage.render({
            elem: 'page',
            count: '{$page.total}',
            theme: '#1E9FFF',
            limit: '{$page.limit}',
            curr: '{$page.page}',
            jump: function (obj, first) {
                if (!first) {
                    window.location.href = '?page='+obj.curr + '&keyword={$keyword}&memberId={$memberId}'
                }
            }
        });
    })

    $(".check-all1").click(function() {
		$(".ids1").prop("checked", this.checked);
	});
	$(".ids1").click(function() {
		var option = $(".ids1");
		option.each(function(i) {
			if (!this.checked) {
				$(".check-all1").prop("checked", false);
				return false;
			} else {
				$(".check-all1").prop("checked", true);
			}
		});
	});

</script>
{/block}